package com.kerrykidz.system.util.security;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.shiro.SecurityUtils;

import com.kerrykidz.system.dao.model.SecUsrEntity;
import com.kerrykidz.system.vo.UserInfo;

/**
 * 用户验证成功后的身份信息
 * 
 * @author 奎哥
 * 
 */
public class PrincipalInfo extends UserInfo implements Serializable {

	private static final long serialVersionUID = 8267422219690297288L;

	public PrincipalInfo(SecUsrEntity usr) {
		super.userId = usr.getPkUsrId();
		super.name = usr.getUsrName();
		super.jobLvl = usr.getJobLvl();
		super.loginId = usr.getLoginId();
		super.loginPwd = usr.getLoginPwd();
		super.branId = usr.getFkBranId();
		super.abbrCode = usr.getAbbrCode();
		super.branName = usr.getBranName();
	}

	private Set<PermissionObj> permissions;

	private Map<String, List<String>> urlsLinks;

	private String menus;

	@Override
	public int hashCode() {
		return super.userId.hashCode();
	}

	@Override
	public String toString() {
		return this.loginId.toString();
	}

	@Override
	public boolean equals(Object obj) {
		return this == obj || this.userId.equals(obj);
	}

	public String getUsername() {
		return super.getLoginId();
	}

	public Set<PermissionObj> getPermissions() {
		return permissions;
	}

	public void setPermissions(Set<PermissionObj> permissions) {
		this.permissions = permissions;
	}

	public String getMenus() {
		return menus;
	}

	public void setMenus(String menus) {
		this.menus = menus;
	}

	public void setRoleList(List<String> roleList) {
		this.roleList = roleList;
	}

	public Map<String, List<String>> getUrlsLinks() {
		return urlsLinks;
	}

	public void setUrlsLinks(Map<String, List<String>> urlsLinks) {
		this.urlsLinks = urlsLinks;
	}

	public void setContAddr(String contAddr) {
		super.contAddr = contAddr;
	}

	public static PrincipalInfo getInstance() {
		return (PrincipalInfo) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
	}

}
